<template>
	<view>
		<u-sticky>
			<view class="navtop">
				<view class="status_bar">
					<!-- 这里是状态栏 -->
				</view>
				<view class="navtitle">
					{{name}}
					<view class="icon" @click="fanhui()">
						<u-icon name="arrow-left" color="#fff" size="20"></u-icon>
					</view>
				</view>
			</view>
		</u-sticky>
		<!-- 中间 -->
		<view class="" style="text-align: center;margin-top: 50rpx;" v-if="Boutique.length === 0">
			<image src="/static/no.png" mode="scaleToFill"
				style="margin-top: 100rpx;width: 300rpx;height: 300rpx;"></image>
			<view class="" style="color: #999;font-size: 28rpx;margin-top: 20rpx;">
				暂无
			</view>
		</view>
		<view class="main" v-else>
			<scroll-view scroll-y="true" @scrolltolower="scrolltolower">
				<view class="cont flex-row">
					<view class="commodity" v-for="(item,index) in Boutique" :key="index" @click="details(item.id)">
						<view class="imag">
							<image :src="item.fileName" mode="aspectFill"></image>
						</view>
						<view class="commobott">
							<view class="tit">
								{{item.storeName}}
							</view>
							<view class="originalcost">
								<text>￥</text>
								{{item.otPrice}}
							</view>
							<view class="pricebox">
								<view class="price">
									<text>￥</text>
									{{item.price}}
								</view>
								<view class="right">
									已售{{item.sales}}
								</view>
							</view>
						</view>

					</view>
				</view>
			</scroll-view>
		</view>
		<view class="" v-show="isOver">
			<u-loadmore :status="status" />
		</view>
		<view class="bottom"></view>
	</view>
</template>

<script>
	import {
		getListByType
	} from '@/api/shoppingMall.js'
	export default {
		data() {
			return {
				Boutique: [],
				pageNum: 1,
				pageSize: 10,
				isOver: false, //用来显示显隐提示语 isOver 默认值false
				status: 'loading',
				typeId: 0, // 分类id
				name: '' // 分类名称
			}
		},
		//下拉到底部后加载新数据
		onReachBottom() {
			this.isOver = true;
			this.pageNum++; //页数加一
			this.BoutiqueList(); //回调接口
		},
		onLoad(option) {
			if (option.id) {
				this.typeId = option.id
				this.name = option.name
				this.BoutiqueList()
			}
		},
		created() {
			this.BoutiqueList()
		},
		methods: {
			scrolltolower() {

			},
			details(id) {
				uni.navigateTo({
					url: '/subPackages/pages/shoppingmall/productDetails/productDetails?id=' + id
				});
			},
			BoutiqueList() {
				const data = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					cateId: this.typeId
				}
				getListByType(data).then(res => {
					const count = res.total
					if (this.Boutique.length === count) {
						this.status = 'normal'
						return
					}

					this.Boutique = [...this.Boutique, ...res.rows]
				})
			},
			fanhui() {
				uni.navigateBack({

				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.navtop {
		background-image: linear-gradient(to right, #6CBEFF, #1989E1, #1989E1);

		overflow: hidden;

		.status_bar {
			height: var(--status-bar-height);
			width: 100%;
		}

		.navtitle {
			text-align: center;
			font-size: 32rpx;
			color: #fff;
			padding: 20rpx 0;
		}
	}

	.icon {
		position: absolute;
		left: 20rpx;
		top: 70rpx;
	}

	.main {
		width: 96%;
		margin: 20rpx 0 0 2%;
		background-color: #FFFFFF;
	}


	.cont {
		margin: 20rpx 2% 0 2%;
		justify-content: space-between;
		flex-wrap: wrap;

		.commodity {
			width: 336rpx;
			margin-bottom: 30rpx;

			.imag {
				width: 336rpx;
				height: 336rpx;

				image {
					width: 336rpx;
					height: 336rpx;
				}
			}

			.commobott {
				padding: 20rpx;

				.tit {
					font-size: 28rpx;
					height: 80rpx;
					color: #333;
				}

				.pricebox {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.price {
						color: #FF1A00;
						font-size: 32rpx;
						font-weight: bold;

						text {
							font-size: 24rpx;
						}
					}

					.right {
						font-size: 24rpx;
						color: #999;
					}
				}

				.originalcost {
					color: #999;
					font-size: 20rpx;
					text-decoration: line-through;
					height: 25rpx;
					margin: 30rpx 0 10rpx
				}
			}

		}

	}

	.bottom {
		width: 100%;
		height: 300rpx;
	}
</style>
